<template>
    <div class="shopcart">
        <div class="shopcartContent">
            <div class="content">
                <div class="recommend">
                    <div class="title">
                        <div class="titleLeft">{{ headerLine1.promTitle }}</div>
                        <div class="titleCenter">{{ headerLine1.promTip }}</div>
                        <div class="titleRight">{{ headerLine1.promotionTip }}></div>
                    </div>
                    <div class="swiper">
                        <van-swipe :loop="false" :width="225" height="70" indicator-color="transparent">
                            <van-swipe-item v-for="item in recommendGoods" :key="item.uniqueId">
                                <div class="item_list">
                                    <div class="item_img">
                                        <img :src="item.pic" alt="" />
                                    </div>
                                    <div class="item_content">
                                        <div class="content_top">{{ item.itemName }}</div>
                                        <div class="content_center">{{ item.itemName.split('，')[1] }}</div>
                                        <div class="content_bottom">
                                            <div class="bottom_left">{{ item.priceTag }}</div>
                                            <div class="bottom_center">
                                                <span class="center_icon">
                                                    {{ item.showActualPrice }}
                                                </span>
                                                <span class="onsale">{{ item.showRetailPrice }}</span>
                                            </div>
                                            <div class="bottom_right">
                                                <van-icon name="cart-circle-o" />
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </van-swipe-item>
                            <van-swipe-item style="width: 77px">
                                <div class="swiper_more">
                                    查看全部
                                    <van-icon name="arrow" />
                                </div>
                            </van-swipe-item>
                        </van-swipe>
                    </div>
                    <div class="recommend_bottom"></div>
                </div>
            </div>
            <div class="goods">
                <div class="goods_title">
                    <span class="title_icon" :class="{ active: checked }">
                        <van-icon name="success" />
                    </span>
                    <div class="title_sale">{{ goodsHeader.groupTitle }}</div>
                    <div class="title_center">{{ goodsHeader.groupTip }}</div>
                    <div class="title_right">{{ goodsHeader.toGoTip }}></div>
                </div>
                <van-swipe-cell v-for="(good, index) in goodsListData" :key="good.uniqueId">
                    <div class="item_icon">
                        <span :class="{ active: good.checked }"><van-icon name="success" /></span>
                    </div>
                    <div class="discountPrice">
                        <span class="text">优惠后:</span>
                        <span>{{ good.discountPrice }}</span>
                    </div>
                    <van-card :num="good.cnt" :price="good.retailPrice.toString() + '.00'"
                        :desc="good.specList[0]?.specValue" :title="good.prefix + ' ' + good.itemName" class="goods-card"
                        :thumb="good.pic" />
                    <template #right>
                        <van-button square @click="deleteGoods(index)" text="删除" type="danger" class="delete-button" />
                    </template>
                    <div class="jinggao"><van-icon name="fail" />{{ good.bottomTips[0].value }}</div>
                </van-swipe-cell>
            </div>
            <div>
                <van-submit-bar class="submitBar" :price="Number(priceData.showActualPrice?.split(':')[1]?.slice(1)) * 100"
                    button-text="结算">
                    <van-checkbox v-model="checked">全选</van-checkbox>
                    <template #tip>
                        <div class="free">
                            <div class="free-icon">
                                <img src="https://yanxuan.nosdn.127.net/98e742f093afd67b52fd085f41179572.png" />
                            </div>
                            <div class="free-center">开通Pro会员，享天天免邮</div>
                            <div class="free-right">立即开通 ></div>
                        </div>
                    </template>
                    <div class="preferential" @click="dialogShow">{{ priceData.showActivityPrice }}
                        <img class="icon" src="https://yanxuan.nosdn.127.net/static-union/1670384798a33c77.png" alt="">
                    </div>
                </van-submit-bar>
                <!-- 弹出框 -->
                <van-dialog class="dialog" v-model:show="show" title="金额明细" width="375px" :show-confirm-button="false">
                    <div class="line line1">
                        <span>商品总价</span>
                        <span class="num">￥428</span>
                    </div>
                    <div class="line line2">
                        <span>优惠合计</span>
                        <span>-￥120</span>
                    </div>
                    <div class="line line3">
                        <span>限时购</span>
                        <span>-￥20</span>
                    </div>
                    <div class="line line4">
                        <span>特价</span>
                        <span>-￥100</span>
                    </div>
                    <div class="line line5">
                        <span>合计</span>
                        <span>308</span>
                    </div>
                    <img class="close" @click="closeDialog"
                        src="https://yanxuan.nosdn.127.net/static-union/1670393037a016b4.png" alt="">
                </van-dialog>
            </div>
        </div>
        <Tabbar></Tabbar>
    </div>
</template>

<script lang="ts">
import { defineComponent } from "vue"
export default defineComponent({
    name: 'ShopCart',
})
</script>

<script lang="ts" setup>
import { ref, onMounted, computed } from 'vue'
import Tabbar from '@/components/Tabbar/index.vue'
import { useShopcartStore } from '@/stores/moduls/shopcart'
import { storeToRefs } from 'pinia'
const show = ref(false);
function dialogShow() {
    show.value = true
}
function closeDialog() {
    show.value = false
}

const shopcartStore = useShopcartStore()
function getShopCartData() {
    shopcartStore.getShopCartData()
}
let { headerLine1, recommendGoods, goodsHeader, goodsListData, priceData } = storeToRefs(shopcartStore)

onMounted(() => {
    getShopCartData()
})
const checked = computed({
    get() {
        return goodsListData.value.every((item: { checked: any }) => item.checked)
    },
    set() {
        goodsListData.value.forEach((item: { checked: boolean }) => {
            item.checked = !item.checked
        });
    }
})
function deleteGoods(index: number) {
    goodsListData.value.splice(index, 1)
}

</script>

<style lang="less" scoped>
.shopcart {
    width: 375px;
    height: 100vh;
    position: relative;
    background-color: #f4f4f4;


    .shopcartContent {
        overflow: scroll;
        padding-bottom: 140px;

        .dialog {
            position: relative;

            .close {
                position: absolute;
                top: 23px;
                right: 15px;
                width: 14.5px;
                height: 14.5px;
            }
            .line{
                display: flex;
                justify-content: space-between;
                margin: 0 12px;
            }

            .line1 {
                height: 48px;
                line-height: 48px;
                font-size: 16px;
                color: #333;
                font-weight: 600;
            }
            .line2 {
                height: 48px;
                line-height: 48px;
                font-size: 16px;
                color: #fa1e32;
                font-weight: 600;
            }
            .line3{
                font-size: 14px;
                height: 24px;
                margin-bottom: 5px;
            }
            .line4{
                font-size: 14px;
                height: 24px;
                margin-bottom: 5px;
            }
            .line5 {
                height: 48px;
                line-height: 48px;
                margin-top: 95px;
                font-size: 16px;
                color: #333;
                font-weight: 600;
            }
        }

        .free {
            display: flex;
            padding: 0 20px;
            height: 40px;
            line-height: 40px;
            width: 100%;
            box-sizing: border-box;
            background-color: #ffe0bd;
            border-top-right-radius: 10px;
            border-top-left-radius: 10px;

            .free-icon {
                img {
                    width: 13px;
                    height: 13px;
                }
            }

            .free-center {
                margin-left: 6px;
                font-size: 12px;
                flex: 1;
            }

            .free-right {
                font-size: 12px;
                color: #fa1e32;
            }
        }
    }

}

.content {
    padding: 10px 10px 0;

    .recommend {
        background-color: #fff;
        border-radius: 10px;
        height: 145px;

        .title {
            display: flex;
            padding: 0 12px;
            display: flex;
            align-items: center;
            height: 44px;

            .titleLeft {
                font-weight: bold;
                font-size: 16px;
            }

            .titleCenter {
                flex: 1;
                text-align: right;
                color: #333;
                margin-right: 8px;
            }

            .titleRight {
                color: #fa1e32;
            }
        }

        .swiper {
            padding: 4px 12px 8px;

            .van-swipe-item {
                margin-right: 10px;
                padding-right: 8px;
                height: 70px;
                box-sizing: border-box;
                border-radius: 8px;

                .item_list {
                    display: flex;
                    background-color: #fafafa;
                    border-radius: 10px;

                    .item_img {
                        img {
                            width: 70px;
                            height: 70px;
                        }
                    }

                    .item_content {
                        display: flex;
                        flex-direction: column;
                        justify-content: center;
                        overflow: hidden;
                        margin-left: 8px;

                        /* 溢出隐藏 */
                        .content_top {
                            text-overflow: ellipsis;
                            /* 溢出显示省略号 */
                            overflow: hidden;
                            /* 溢出隐藏 */
                            white-space: nowrap;
                            /* 强制不换行 */
                        }

                        .content_center {
                            color: #999;
                            font-size: 12px;
                            text-overflow: ellipsis;
                            /* 溢出显示省略号 */
                            overflow: hidden;
                            /* 溢出隐藏 */
                            white-space: nowrap;
                            /* 强制不换行 */
                        }

                        .content_bottom {
                            display: flex;
                            align-items: center;

                            .bottom_left {
                                color: #fa1e32;
                            }

                            .bottom_center {
                                flex: 1;

                                .center_icon {
                                    font-weight: bold;
                                    font-size: 16px;
                                    color: #fa1e32;
                                }

                                .onsale {
                                    color: #7f7f7f;
                                }
                            }

                            .bottom_right {
                                color: #fa1e32;
                                font-size: 14px;
                            }
                        }
                    }
                }

                .swiper_more {
                    padding: 0 10px;
                    width: 77px;
                    height: 70px;
                    line-height: 70px;
                    color: #fa1e32;
                    background-color: #fafafa;
                    border-radius: 10px;
                }
            }
        }

        .recommend_bottom {
            height: 20px;
        }
    }
}

::v-deep(.van-icon) {
    font-size: larger
}
::v-deep(.van-icon::before) {
    // margin-left: 15px;
    // margin-top: 5px;
}

::v-deep(.van-image) {
    background-color: #F4F4F4;
}

.goods {
    border-radius: 10px;
    margin: 10px;
    padding: 5px 0;
    background-color: #fff;
    position: relative;



    .item_icon {
        line-height: 90px;
        margin-right: 5px;
        display: flex;
        align-items: center;
        position: absolute;
        top: 31px;
        left: 9px;
        z-index: 100000;

        span {
            width: 19px;
            height: 19px;
            border-radius: 50%;
            border: 1px solid #e6e6e6;
            color: #fff;
            text-align: center;
            line-height: 19px;

            &.active {
                background-color: #fa1e32;
            }
        }
    }

    .discountPrice {
        line-height: 90px;
        margin-right: 5px;
        display: flex;
        align-items: center;
        position: absolute;
        top: 25px;
        left: 182px;
        z-index: 100000;
        color: #fa1e32;
        font-size: 14px;
        font-weight: 600;

        .text {
            font-size: 12px;
        }
    }

    .goods_title {
        background-color: #fff;
        padding: 0 12px;
        display: flex;
        height: 44px;
        align-items: center;

        .title_icon {
            width: 19px;
            height: 19px;
            margin-right: 8px;
            line-height: 19px;
            text-align: center;
            color: #fff;
            border-radius: 50%;
            border: 1px solid #e6e6e6;

            &.active {
                background-color: #fa1e32;
            }
        }

        .title_sale {
            font-size: 16px;
            color: #333;
            font-weight: 600;
        }

        .title_center {
            flex: 1;
            text-align: right;
            margin-right: 8px;
        }

        .title_right {
            color: #E74547;
        }

    }

    .goods_list {
        background-color: #fff;
        padding: 12px 0;

        .item {
            .item_detail {
                padding: 0 12px;
                display: flex;
                flex-shrink: 0;
                height: 90px;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;

                .item_icon {
                    line-height: 90px;
                    margin-right: 5px;
                    display: flex;
                    align-items: center;

                    span {
                        width: 19px;
                        height: 19px;
                        border-radius: 50%;
                        border: 1px solid #e6e6e6;
                        color: #fff;
                        text-align: center;
                        line-height: 19px;

                        &.active {
                            background-color: #fa1e32;
                        }
                    }
                }

                .item_img {
                    width: 90px;
                    height: 90px;
                    border-radius: 5px;

                    img {
                        width: 90px;
                        height: 90px;
                    }
                }

                .item_content {
                    width: 205px;
                    box-sizing: border-box;
                    margin-left: 14px;
                    flex: 1;

                    .content_top {
                        display: flex;
                        overflow: hidden;
                        text-overflow: ellipsis;
                        white-space: nowrap;

                        .top_left {
                            margin-right: 8px;
                            white-space: nowrap;
                            font-size: 14px;
                            color: #fa1e32;
                        }

                        .top_right {
                            font-size: 12px;
                            color: #999;
                            text-align: right;
                            text-overflow: ellipsis;
                            white-space: nowrap;
                            overflow: hidden;
                        }
                    }

                    .content_center {
                        padding: 0 10px 0 6px;
                        height: 18px;
                        border-radius: 18px;
                        line-height: 18px;

                        .center_font {
                            background-color: #f4f4f4;
                            display: flex;
                            align-items: center;
                            color: #7f7f7f;
                        }

                        .center_icon {
                            margin-left: 5px;
                        }
                    }

                    .content_bottom {
                        margin-top: 5px;
                        display: flex;
                        align-items: center;
                        font-size: 14px;

                        .bottom_left {
                            display: flex;
                            flex: 1;

                            .bottom_originprice {
                                font-weight: bold;

                                .price {
                                    font-size: 20px;
                                }
                            }

                            .bottom_nowprice {
                                color: #fa1e32;

                                .now_price {
                                    margin-left: 3px;
                                    font-size: 12px;
                                    font-weight: bold;
                                }
                            }
                        }

                        .bottom_count {
                            text-align: center;
                            border: 1px solid #7f7f7f;
                            border-radius: 28px;
                            padding: 0 8px;
                            width: 34px;
                            height: 28px;
                            line-height: 28px;
                        }
                    }
                }
            }
        }

        .item_info {
            margin-top: 4px;
            padding: 0 12px 0 15px;
            color: #7f7f7f;

            .info_list {
                display: flex;

                .jinggao {
                    margin: 2px 0 2px 5px;
                }
            }
        }


    }

    .jinggao {
        padding-left: 35px;
        color: #7f7f7f;
    }

    .itemList {
        margin-left: 35px;
        margin-right: 10px;
        padding-left: 10px;
        background-color: #f4f4f4;
        list-style-type: disc;
        list-style-position: inside;

        li {
            margin: 10px 3px 0 0;
            color: #999;

        }
    }

}

::v-deep(.van-card__title) {
    color: #333;
    font-size: 14px;
    font-weight: normal;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

::v-deep(.van-multi-ellipsis--l2) {
    display: block;
}

::v-deep(.van-card__desc) {
    color: #7f7f7f;
    font-size: 12px;
    width: 194px;
}

::v-deep(.van-ellipsis) {
    overflow: visible;
    white-space: normal;
}

::v-deep(.van-card__num) {
    position: absolute;
    top: 25px;
    right: -7px;
}

::v-deep(.van-card__price) {
    position: absolute;
    top: 50px;
    left: 0;
}

::v-deep(.van-badge__wrapper.van-icon.van-icon-fail) {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 1px solid #7f7f7f;

    &::before {
        width: 10px;
        height: 10px;
        color: #7f7f7f;
    }
}

::v-deep(.van-card) {
    padding-left: 35px;
}

::v-deep(.van-icon) {
    font-size: small;
}

.submitBar {
    bottom: 50px;

    .preferential {
        padding-right: 10px;
        position: absolute;
        bottom: 10px;
        left: 136px;
        z-index: 111111;
        font-size: 12px;


        .icon {
            position: absolute;
            top: 6px;
            right: 0px;
            width: 9.5px;
            height: 5.5px;
            z-index: 111111;
        }
    }
}

::v-deep(.van-submit-bar__text) {
    height: 21px;
    font-size: 14px;
    margin-top: -10px;
}

::v-deep(.van-submit-bar__price-integer) {
    font-size: 14px;
}

::v-deep(.van-submit-bar__bar) {
    width: 375px;
    height: 59px;
    background-color: #fafafa;
    position: relative;
}

::v-deep(.van-submit-bar__tip) {
    width: 375px;
}

::v-deep(.van-badge__wrapper) {
    width: 19px;
    height: 19px;
    margin-right: 15px;
}

::v-deep(.van-checkbox__label) {
    margin: 0;
    font-weight: 200;
    color: #7f7f7f;
}

// 弹出框样式
::v-deep(.van-popup) {
    margin: 0;
    width: 375px;
    height: 355px;
    border-radius: 0;
    top: 380px;
}

::v-deep(.van-popup--center) {
    max-width: 100vw;
}

::v-deep(.van-overlay) {
    height: 80%;
}

::v-deep(.van-dialog__header) {
    height: 60px;
    line-height: 60px;
    padding: 0 0 15px 0;
    font-size: 17px;
    color: #333;
}

::v-deep(.van-submit-bar__tip) {
    padding: 0;
}

::v-deep(.van-checkbox__icon--checked .van-icon) {
    background-color: #E63A3C;
    border-color: #E63A3C;
}

.goods-card {
    margin: 0;
    background-color: white;
}

.delete-button {
    height: 100%;
}</style>